package com.LA_houseLease.admin.service.impl;


import com.LA_houseLease.admin.mapper.SystemPostMapper;
import com.LA_houseLease.admin.mapper.SystemUserMapper;
import com.LA_houseLease.admin.service.SystemPostService;
import com.LA_houseLease.admin.vo.system.user.SystemUserItemVo;
import com.LA_houseLease.admin.vo.system.user.SystemUserQueryVo;
import com.LA_houseLease.common.exception.houseLeaseException;
import com.LA_houseLease.common.result.ResultCodeEnum;
import com.LA_houseLease.pojo.entity.SystemPost;
import com.LA_houseLease.pojo.entity.SystemUser;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;

/**
* @author liubo
* @description 针对表【system_post(岗位信息表)】的数据库操作Service实现
* @createDate 2023-07-24 15:48:00
*/
@Service
public class SystemPostServiceImpl extends ServiceImpl<SystemPostMapper, SystemPost>
    implements SystemPostService {

    @Autowired
    private SystemUserMapper systemUserMapper;

    /**
     * 根据id删除岗位
     * @param id
     */
    @Override
    public void removeSystemPostById(Long id) {
        //判断当前岗位是否有管理系统用户
        LambdaQueryWrapper<SystemUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SystemUser::getPostId,id);
        List<SystemUser> systemUsers = systemUserMapper.selectList(lambdaQueryWrapper);
        if(CollectionUtils.isEmpty(systemUsers)){
            super.removeById(id);
        }else{
            throw new houseLeaseException(ResultCodeEnum.SYSTEM_DELETE_ERROR);
        }
    }

}
















